package org.lynn.javax.demo.jframe;

/**
 * @author linzou@linkdoc.com
 * @ClassName: Circle
 * @Description:
 * @date 2019/6/20 8:22 AM
 */
public class Circle {

    public int x;
    public int y;
    public int vx;
    public int vy;
    private int r;

    public Circle(int x, int y, int vx, int vy, int r) {
        this.x = x;
        this.y = y;
        this.vx = vx;
        this.vy = vy;
        this.r = r;
    }

    public int getR() {
        return r;
    }


    public void move(int minx, int miny, int maxx, int maxy){
        x += vx;
        y += vy;

        checkCollision(minx, miny, maxx, maxy);
    }

    private void checkCollision(int minx, int miny, int maxx, int maxy){

        if(x - r < minx) { x = r;        vx = -vx; }
        if(x + r >= maxx){ x = maxx - r; vx = -vx; }
        if(y - r < miny) { y = r;        vy = -vy; }
        if(y + r >= maxy){ y = maxy - r; vy = -vy; }
    }
}
